var t = require("../../../utils/api.js"), a = getApp();

Page({
    data: {
        status: 10,
        item: {
            status: "待付款"
        },
        data: "",
        page: 2
    },
    onLoad: function(o) {
        var e = this;
        wx.showLoading({
            title: "加载中"
        });
        var n = 10;
        console.log(o.status), "" != o.status && void 0 != o.status && (n = o.status, e.setData({
            status: n
        })), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), t.getFraction_order({
            openid: a.globalData.openid,
            status: n
        }).then(function(t) {
            console.log(t), 0 == t.data.status && e.setData({
                data: t.data.data
            }), wx.hideLoading();
        });
    },
    myTab: function(o) {
        wx.showLoading({
            title: "加载中"
        });
        var e = this, n = o.currentTarget.dataset.id;
        t.getFraction_order({
            openid: a.globalData.openid,
            status: n
        }).then(function(t) {
            console.log(t), 0 == t.data.status && e.setData({
                data: t.data.data,
                page: 2
            }), e.setData({
                status: n
            }), wx.hideLoading();
        });
    },
    orderRevoke: function(o) {
        var e = this, n = o.currentTarget.dataset.id;
        wx.showModal({
            title: "提示",
            content: "是否取消该订单？",
            cancelText: "否",
            confirmText: "是",
            success: function(o) {
                console.log(o), o.confirm && t.getFraction_order_info({
                    openid: a.globalData.openid,
                    id: n
                }).then(function(o) {
                    console.log(o.data), o.data.status, wx.showLoading({
                        title: o.data.msg
                    }), t.getFraction_order({
                        openid: a.globalData.openid
                    }).then(function(t) {
                        0 == t.data.status && e.setData({
                            data: t.data.data
                        }), wx.hideLoading();
                    });
                });
            }
        });
    },
    orderConfirm: function(o) {
        var e = this, n = o.currentTarget.dataset.id;
        wx.showModal({
            title: "提示",
            content: "是否确认收货？",
            cancelText: "否",
            confirmText: "是",
            success: function(o) {
                o.confirm && t.getFraction_pick_up_goods({
                    openid: a.globalData.openid,
                    id: n
                }).then(function(o) {
                    console.log(o), 0 == o.data.status ? (wx.showLoading({
                        title: o.data.msg
                    }), t.getFraction_order({
                        openid: a.globalData.openid,
                        status: e.data.status
                    }).then(function(t) {
                        0 == t.data.status && e.setData({
                            data: t.data.data
                        });
                    })) : wx.showLoading({
                        title: o.data.msg
                    }), wx.hideLoading();
                });
            }
        });
    },
    onReachBottom: function(o) {
        wx.showLoading({
            title: "努力加载中"
        });
        var e = this, n = e.data.page;
        t.getFraction_order({
            openid: a.globalData.openid,
            status: e.data.status,
            page: n
        }).then(function(t) {
            if (0 == t.data.status) {
                n = parseInt(n) + parseInt(1);
                var a = t.data.data;
                a = e.data.data.concat(a), e.setData({
                    data: a,
                    page: n
                });
            }
            wx.hideLoading();
        });
    },
    orderSubmitPay: function(o) {
        wx.showLoading({
            title: "加载中"
        });
        var e = this, n = o.currentTarget.dataset.id;
        t.getFraction_order_pay({
            openid: a.globalData.openid,
            id: n
        }).then(function(o) {
            console.log(o), 0 == o.data.status ? wx.requestPayment({
                timeStamp: o.data.data.timeStamp,
                nonceStr: o.data.data.nonceStr,
                package: o.data.data.package,
                signType: "MD5",
                paySign: o.data.data.paySign,
                success: function(n) {
                    t.getFraction_shopping_order({
                        id: o.data.data.id,
                        openid: a.globalData.openid
                    }).then(function(o) {
                        0 == o.data.status ? (wx.showLoading({
                            title: "支付成功"
                        }), setTimeout(function() {
                            t.getFraction_order({
                                openid: a.globalData.openid
                            }).then(function(t) {
                                console.log(t), 0 == t.data.status && (e.setData({
                                    data: t.data.data
                                }), wx.hideLoading());
                            });
                        }, 2e3)) : wx.showModal({
                            title: "提示",
                            content: o.data.msg,
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && console.log("用户点击确定");
                            }
                        });
                    });
                },
                fail: function(t) {
                    wx.showLoading({
                        title: "支付失败"
                    });
                }
            }) : wx.showLoading({
                title: o.data.msg
            }), wx.hideLoading();
        });
    }
});